import { fetchGood } from '../../../services/good/fetchGood';

Page({
  data: {
    primaryImage: '',
    context: '',
    navigation: { type: 'fraction' },
    current: 0,
    autoplay: true,
    duration: 500,
    interval: 5000,
  },
  getDetail(saasId) {
    Promise.all([fetchGood(saasId)]).then((res) => {
      const [details] = res;
      const {
        primaryImage,
        otherImages,
        context,
      } = details[0];
      // otherImages.unshift(primaryImage);
      this.setData({
        primaryImage,
        images: otherImages,
        context,
      });
    });
  },

  onShareAppMessage: function () {
    return {
      title: '枫味日记',
      path: '/pages/home/home',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },
  onShareTimeline: function () {
    return {
      title: '枫味日记',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },

  onLoad(query) {
    const { saasId } = query;
    this.setData({
      saasId: saasId,
    });
    this.getDetail(saasId);
  },
});
